import { lazy } from 'react'
import qs from 'query-string'
// import IndexPage  from '../view/index/IndexPage'
// import Topic from '../view/topic/Topic'
// import GetStart from '../view/getstart/Getstart'
// import About from '../view/about/About'
// import User from '../view/user/User'
// import Page04 from '../view/page404/Page04'
const types = ['all', 'good', 'share', 'ask', 'job', 'dev']
const IndexPage = lazy(() => import('../view/index/IndexPage'))
const Topic = lazy(() => import('../view/topic/Topic.jsx'))
const GetStart = lazy(() => import('../view/getstart/Getstart.jsx'))
const About = lazy(() => import('../view/about/About.jsx'))
const User = lazy(() => import('../view/user/User.jsx'))
const Page04 = lazy(() => import('../view/page404/Page04'))
export default [
  {
    path: '/indexpage',
    render(props) {
      let { search } = props.location

      search = qs.parse(search)
      let { tab, page } = search
      //当url不是指定的参数的时候展示404
      if (
        (tab == undefined && page == undefined) ||
        (types.indexOf(tab) != -1 && (page == undefined || page > 0))
      ) {
        return <IndexPage {...props}></IndexPage>
      } else {
        return <Page04 {...props}></Page04>
      }
    }
  },
  {
    path: '/topic/:id',
    render(props) {
      return <Topic {...props}></Topic>
    }
  },
  {
    path: '/getstart',
    render(props) {
      return <GetStart {...props}></GetStart>
    }
  },
  {
    path: '/user/:name',
    render(props) {
      return <User {...props}></User>
    }
  },
  {
    path: '/about',
    render(props) {
      return <About {...props}></About>
    }
  }
]
